﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using System;
using System.Runtime.InteropServices;
using Beyond;
using Beyond.Ant;

public class AppDelegate : BEApplication {

    static AppDelegate()
    {
        UnityHelper.InitEnvironment();
    }
    public static bool isDomestic = false;
    public static bool isOppoChinnel = false;
    public static bool isShowAds = false;

    protected override void OnApplicationEnter() {
        InPromotion.setStyle(InPromotion.Style.FullPortrait);
        App.initialize(1088, 1, 63000, "");
        //App.SetPauseFunc (delegate (){
        //});
        //App.SetResumeFunc(delegate (){
        //});  //如果游戏声音问题有特别需求，则填上特别需求，如没有则注释掉，采用系统默认，直接播放视频就行，不需要主动调用pause resume
        //AppInfo.state = AppInfo.State.release;
    }

    protected override void OnApplicationStageEnter() {
        Debug.Log("AppDelegate.OnApplicationStageEnter >>>");
        int chid = AppInfo.getChannelId();
        
        if(chid == 15000)
        {
            isOppoChinnel = true;
            isDomestic = true;
        }
        if (chid == 15000 || chid == 30000 || chid == 29000)
        {
            isDomestic = true;
            isShowAds = true;
        }
        PurchaseProxy.init();
        AdsProxy.init();
        //SnsProxy::init();

        //dd_ant::BEAnt::setDAPBlockUIFunc([=](dd_net::DDPHttpClient *client)
        //{
        //    CCLayer *layer = CCLayer::create();
        //    layer->addChild(CCLayerColor::create(ccc4(0, 0, 0, 128)));
        //    layer->setTouchEnabled(true);
        //    layer->setTag(9999);
        //    CCDirector::sharedDirector()->getRunningScene()->addChild(layer, 1024);
        //}, [=](dd_net::DDPHttpClient *client)
        //{
        //    CCDirector::sharedDirector()->getRunningScene()->removeChildByTag(9999, true);
        //});
        //dd_ant::UserSession::keepAlive();
    }

    public override void onPause() {
        BEAnt.sendPushNotifications();
    }

    public override void onResume() {
        BEAnt.clearPushNotifications();
    }

    public void Update() 
    {
        // if(SceneManager.GetActiveScene().name == "Home")
        //     return;
        if (Input.GetKeyDown(KeyCode.Escape)) {
            Debug.Log($"App.exit...");
            App.exit();
        }
    }

}
